package leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 描述:二叉树中序遍历
 *
 * @author Madison You
 * @created 21:53
 */
public class Easy_94_InorderTraversal {

    public static void main(String[] args) {
        TreeNode treeNode1 = new TreeNode(3, null, null);
        TreeNode treeNode2 = new TreeNode(4, null, null);
        TreeNode treeNode3 = new TreeNode(4, null, null);
        TreeNode treeNode4 = new TreeNode(3, null, null);
        TreeNode treeNode5 = new TreeNode(2, treeNode1, treeNode2);
        TreeNode treeNode6 = new TreeNode(2, treeNode3, treeNode4);
        TreeNode treeNode = new TreeNode(1, treeNode5, treeNode6);
        List<Integer> integers = new Easy_94_InorderTraversal().inorderTraversal(treeNode);
        System.out.println(Arrays.toString(integers.toArray()));
    }

    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        traversal(root, list);
        return list;
    }

    public void traversal(TreeNode root, List<Integer> list) {
        if (root != null) {
            traversal(root.left, list);
            list.add(root.val);
            traversal(root.right, list);
        }
    }


}
